//
//  LGAppointHomeCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/20.
//

#import "LGAppointHomeCell.h"

@interface LGAppointHomeCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *headView;
/**   */
@property (nonatomic , strong)UILabel *typeLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *vipIcon;
/**  风险预警 */
@property (nonatomic , strong)UIImageView *riskView;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;

@end

@implementation LGAppointHomeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.ageLabel.hidden = NO;
    self.typeLabel.hidden = NO;
    NSDictionary *patientDic = dataDic[@"patient"];
    [self.headView sd_setImageWithURL:[NSURL URLWithString:LGNSString(patientDic[@"avatar_url"])]];
    self.ageLabel.text = [NSString stringWithFormat:@"%@ | %@岁",patientDic[@"gender"],patientDic[@"age"]];
    self.contentLabel.text = LGNSString(dataDic[@"situation"]);
    //死亡标记
    if([patientDic[@"is_dead"] integerValue]>0){
        self.nameLabel.layer.borderWidth = 0.5;
        self.nameLabel.text = [NSString stringWithFormat:@" %@ ",patientDic[@"realname"]];
    }else{
        self.nameLabel.layer.borderWidth = 0;
        self.nameLabel.text = LGNSString(patientDic[@"realname"]);
    }
    //会员标识
    [self.vipIcon sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"vipicon"])]];
    if([patientDic[@"is_vip"] integerValue]>0){
        self.vipIcon.hidden = NO;
        [self.riskView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(28));
        }];
    }else{
        self.vipIcon.hidden = YES;
        [self.riskView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(6));
        }];
    }
    //风险预警
    if([patientDic[@"risk_level"] integerValue]>0){
        //有风险
        self.riskView.hidden = NO;
        NSString *riskPic = [NSString stringWithFormat:@"风险预警%@",patientDic[@"risk_level"]];
        self.riskView.image = [UIImage imageNamed:riskPic];
    }else{
        //无风险
        self.riskView.hidden = YES;
    }
    //咨询类型
    NSString *type = LGNSString(dataDic[@"appointment_type"]);
    if([type isEqualToString:@"2"]){
        //视频咨询
        self.typeLabel.text = @"视频";
        self.typeLabel.textColor = [UIColor colorWithString:@"#F2B65B"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#FFF1CF"];
        
    }else if([type isEqualToString:@"3"]){
        //专家(图文咨询)
        self.typeLabel.text = @"图文";
        self.typeLabel.textColor = [UIColor colorWithString:@"#4EA469"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#E5F9F2"];
        
    }else if([type isEqualToString:@"4"]){
        //团队咨询
        self.typeLabel.text = @"团队";
        self.typeLabel.textColor = [UIColor colorWithString:@"#8F7EF9"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#DFDAFF"];
    }else{
        self.typeLabel.hidden = YES;
    }
    
    NSString *state = LGNSString(dataDic[@"state"]);
    if([state isEqualToString:@"0"]){
        //未就诊
        self.statusLabel.textColor = [UIColor colorWithString:@"#3291FF"];
    }else if ([state isEqualToString:@"3"]){
        //已逾期
        self.statusLabel.textColor = [UIColor colorWithString:@"#F84D4D"];
    }else{
        self.statusLabel.textColor = [UIColor colorWithString:@"#999999"];
    }
    self.statusLabel.text = LGNSString(dataDic[@"state_name"]);
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.headView];
    [self.headView addSubview:self.typeLabel];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.ageLabel];
    [self.contentView addSubview:self.vipIcon];
    [self.contentView addSubview:self.riskView];
    [self.contentView addSubview:self.statusLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.right.top.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(32));
        make.width.height.equalTo(@(viewPix(46)));
        make.centerY.equalTo(self.contentView);
    }];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.headView);
        make.height.equalTo(@(viewPix(15)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headView.mas_right).offset(viewPix(10));
        make.top.equalTo(self.headView);
        make.height.equalTo(@(viewPix(23)));
    }];
    
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.vipIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.riskView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(viewPix(34)));
        make.height.equalTo(@(viewPix(14)));
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(32));
        make.centerY.equalTo(self.nameLabel);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(5));
        make.right.equalTo(self.contentView).offset(-viewPix(32));
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)headView{
    if(!_headView){
        _headView = [[UIImageView alloc]init];
        _headView.cornerRidus = 8;
        _headView.clipsToBounds = YES;
    }
    return _headView;
}

-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"" colorString:@"#288CFE" textFont:LGFontWeight(11, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _typeLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.layer.borderColor = [UIColor colorWithString:@"#333333"].CGColor;
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)vipIcon{
    if(!_vipIcon){
        _vipIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
        _vipIcon.hidden = YES;
    }
    return _vipIcon;
}

-(UIImageView *)riskView{
    if(!_riskView){
        _riskView = [[UIImageView alloc]init];
        _riskView.hidden = YES;
    }
    return _riskView;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(13) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _statusLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
